#ifndef GLFRAMEBUFFEROBJECT_H
#define GLFRAMEBUFFEROBJECT_H
#include <QtOpenGL>
#include <QOpenGLFunctions>
#include <QTextStream>
class GLFrameBufferObject : protected QOpenGLFunctions
{

public:
    GLFrameBufferObject(short width, short height, short channels);
    ~GLFrameBufferObject();
    GLuint GetFbo()
    {
        return fbo;
    }
    void BindFbo();
    void ReleaseFbo();
    void ReadBuffer();
    bool CreateFbo();
    void CheckFboLimits();
    float* GetBuffer()
    {
        return pBuffer;
    }
    short GetWidth()
    {
        return w;
    }
    short GetHeight()
    {
        return h;
    }
    short GetChannels()
    {
        return c;
    }
    void SetLogTextStreamObj(QTextStream* textStream)
    {
        logTextStream = textStream;
    }
    void SaveBufferToFile(QString fileName);

private:
    void CreateRGBATexture();

protected:
    void initializeGL();

private:
    short w;
    short h;
    short c;//channel

    QTextStream* logTextStream;

    GLuint fbo;
    GLuint colorBuffer;
    GLuint depthBuffer;
    GLuint textureID;
    float* pBuffer;

    int maxColorAttachments;
    int maxFramebufferWidth;
    int maxFramebufferHeight;
    int maxFramebufferSamples;
    int maxFramebufferLayers;


};

#endif // GLFRAMEBUFFEROBJECT_H
